<?php

namespace app\index\controller\test;

use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\Request as Request;

/**
 * Page 控制器
 * Class Page
 * @package app\index\controller\test;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 */
class Page
{

    public function index(Request $request)
    {
        $page = $request->param('page', 1);
        $page_size = $request->param('page_size', 20);

        $start = 1;
        $end = 100;

        $data = [];
        for ($i = $start; $i <= $end; $i++) {
            $data[] = [
                'id' => $i,
                'title' => '第' . $i . '条',
            ];
        }

        $result = [];

        if (is_numeric($page) && is_numeric($page_size)) {
            $from = ($page - 1) * $page_size;
            $result = array_slice($data, $from, $page_size);
        }

        return ApiResponse::success($result);
    }

}
